package at.home.project.login.model;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class dbScreen implements hibernateQuery {

	private Session session;
	private SessionFactory sessionFactory;
	private Transaction transaction;

	public dbScreen() {
		sessionFactory = HibernateUtil.getSessionFactory();
	}

	public void createConnection() {
		session = sessionFactory.openSession();
		transaction = session.beginTransaction();
	}

	@Override
	public boolean isTrueUserandPass(String userName, String PassWord) {
		boolean result = false;
		try {
			createConnection();
			// List<users> user = new ArrayList<users>();
			org.hibernate.Query query = session
					.createSQLQuery(
							"select * FROM USERS WHERE username= :user and userpass= :pass")
					.setString("user", userName).setString("pass", PassWord);
			// user = query.list();
			if (query.executeUpdate() > 0)
				result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public void sessionClose() {
		session.close();
		sessionFactory.close();
	}

}
